package cn.wen.forum.web;

import cn.wen.forum.common.result.JSONResult;
import cn.wen.forum.pojo.entity.User;
import cn.wen.forum.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName UserLoginController
 * @Author By wen
 * @Description
 * @Date 2023/3/16 10:34
 * @Version 1.0
 */
@Controller
@RequestMapping("user")
public class UserLoginController {

    @Autowired
    private IUserService userService;

    /**
     * 用户登录接口
     * @param user
     * @return
     */
    @PostMapping("login")
    @ResponseBody
    public JSONResult login(@RequestBody User user,HttpServletResponse response) throws Exception{
        return userService.login(user,response);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @PostMapping("register")
    @ResponseBody
    public JSONResult register(@RequestBody User user, HttpServletResponse response) {
        return userService.register(user,response);
    }

    /**
     * 退出登录
     * @param request
     * @return
     */
    @PostMapping("logout")
    @ResponseBody
    public JSONResult logout(HttpServletRequest request) {
        return userService.logout(request);
    }


    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("getUserInfo")
    @ResponseBody
    public JSONResult getUserInfo(HttpServletRequest request) throws Exception {
        return userService.getUser(request);
    }
}
